package org.example;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

public class Map_Demo2 {
    public static void main(String[] args) {
        Map<String,String> map = new HashMap<>();
        map.put("超人","雅威");
        map.put("炒人","哈哥");
//键值对 遍历
        Set<Map.Entry<String, String>> entries = map.entrySet();
        //迭代器
        Iterator<Map.Entry<String,String>> it=entries.iterator();
        while(it.hasNext()){
            Map.Entry<String,String> entry=it.next();
            System.out.println(entry.getKey()+"="+entry.getValue());
        }
        //增强for循环
        for (Map.Entry<String,String> entry:entries){
            System.out.println(entry.getKey()+"="+entry.getValue());
        }
        //lamda表达式
        entries.forEach((Map.Entry<String,String> entry)->{
            System.out.println(entry.getKey()+"="+entry.getValue());
        });
        //匿名内部类
        entries.forEach(new Consumer<Map.Entry<String,String>>() {
            @Override
            public void accept(Map.Entry<String,String> entry) {
                System.out.println(entry.getKey()+"="+entry.getValue());
            }
        });
    }
}
